home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Doc / paper.ms < prev    next >
Encoding:
Text File  |  1991-02-28  |  49.9 KB  |  1,434 lines  |  [TEXT/????]

  1. .\" Typeset using refer -e -n | (di)troff -ms.
  2. .\" You may have to change the CW (Constant Width) macro define below
  3. .\" if you aren't typesetting on a PostScript printer.
  4. .\" Your best bet is to change ".ft C" by ".ft I" and "\fC" by "\fI".
  5. .\" Each occurs exactly once in the macro definition.
  6. .de CW
  7. .if t .if "\\$1"" .ft C
  8. .if t .if !"\\$1"" \fC\\$1\fP\\$2
  9. .if n .B "\\$1" "\\$2"
  10. ..
  11. .TL
  12. .nr PD 0
  13. .nr PI 2n
  14. .ft H
  15. .ps 14
  16. STDWIN \- A Standard Window System Interface
  17. .ps
  18. .ft
  19. .AU
  20. .ft H
  21. Guido van Rossum
  22. .ft
  23. .AI
  24. .ft HO
  25. .ps 8
  26. .vs 10
  27. Center for Mathematics and Computer Science
  28. P.O. Box 4079, 1009 AB Amsterdam, The Netherlands
  29. E-mail: guido@cwi.nl or mcvax!guido
  30. .vs
  31. .ps
  32. .ft
  33. .AB
  34. .LP
  35. STDWIN is an interface layer placed between an application written in C
  36. and arbitrary window system, making the use of windows both easier and
  37. more portable.
  38. For applications using STDWIN
  39. for their window management requirements, adaptation to a
  40. different window system is as easy as linking with an appropriate
  41. version of the STDWIN library.
  42. So far, STDWIN libraries are available
  43. for the Apple Macintosh,
  44. for the Whitechapel MG-1 (running Oriel),
  45. for MIT's X Window System version 11,
  46. for the Atari ST,
  47. and (subsets) for alphanumeric terminals on
  48. .UX
  49. and MS-DOS.
  50. .FS
  51. .ft H
  52. .sp
  53. Report CS-R8817
  54. .br
  55. Centre for Mathematics and Computer Science
  56. .br
  57. P.O. Box 4079, 1009 AB Amsterdam, The Netherlands
  58. .ft
  59. .FE
  60. New implementations are easily written.
  61. .PP
  62. Like STDIO, C's Standard I/O library, STDWIN's aim is to give
  63. a simple interface, high-level functionality, and portability.
  64. It does not attempt to allow access to all possible features of window
  65. management systems; rather, it provides the programmer with a
  66. model which allows easy construction of that part of the program which
  67. is concerned with window management.
  68. .PP
  69. STDWIN's high-level operations include automatic window positioning
  70. and resizing, scrolling, menus, keyboard shortcuts, and multiple-click
  71. detection.
  72. .sp
  73. .ps 8
  74. .vs 10
  75. .ft HO
  76. 1980 Mathematics Subject Classification:
  77. .ft
  78. .ft H
  79. 68B20.
  80. .ft
  81. .br
  82. .ft HO
  83. 1982 CR Categories:
  84. .ft
  85. .ft H
  86. D.2.2, I.3.4, I.3.6.
  87. .ft
  88. .br
  89. .ft HO
  90. Key Words & Phrases:
  91. .ft
  92. .ft H
  93. window systems, user interfaces, portability.
  94. .ft
  95. .br
  96. .ft HO
  97. Note:
  98. .ft
  99. .ft H
  100. This paper has been submitted for publication elsewhere.
  101. .ft
  102. .vs
  103. .ps
  104. .AE
  105. .LP
  106. .NH
  107. Introduction
  108. .LP
  109. First, some history.
  110. STDWIN's conception was motivated by the desire to add a more modern
  111. user interface (i.e., one using windows and a mouse)
  112. to the programming environment for the language ABC,
  113. developed here at CWI.
  114. .[
  115. %A Leo Geurts, Lambert Meertens, Steven Pemberton
  116. %T The ABC Programmer's Handbook
  117. %I CWI
  118. %C Amsterdam
  119. %D to be published in 1988
  120. .]
  121. The ABC programming environment, consisting of a syntax-directed editor,
  122. an interpreter and a source file manager, is a large body of C
  123. code which, through careful isolation of system-dependent modules, has
  124. proven to be quite portable, both to different versions of
  125. .UX
  126. and to non-\c
  127. .UX
  128. systems such as MS-DOS and the Apple Macintosh.
  129. Naturally, we did not want to lose its portability by tying
  130. it closely to one particular window system.
  131. .PP
  132. Only after having looked closely at a few existing window systems, we
  133. became fully aware of the problems.
  134. Most window systems offer a large range of facilities, apparently
  135. intended to enable programmers to create beautiful user interfaces,
  136. but often resulting in total chaos.
  137. .[
  138. %A Mike O'Dell
  139. %B EUUG Conference Proceedings, September 1987, Dublin, Ireland
  140. %T What They Don't Tell You About Window Systems
  141. .]
  142. One of the problems appears to be the low level of most window system
  143. interfaces.
  144. For example, on the Apple Macintosh, all tools are provided to
  145. work with scroll bars (bit-scrolling operations, routines to draw scroll
  146. bars, routines to detect user interaction with a scroll bar), but the
  147. amount of code needed to glue these together and create a scrollable
  148. view on a document is horrendous.
  149. .[
  150. %T Inside Macintosh
  151. %A Apple Computer
  152. %I Addison-Wesley
  153. %C Reading, Mass.
  154. %D 1985
  155. .]
  156. Similarly, again on the Macintosh, double-clicking the mouse button is
  157. a frequent form of user input, but there is no library routine available
  158. to detects double-clicks, leading to much code duplication and
  159. gratuitous differences between programs.*
  160. .FS
  161. * In all fairness it should be said that the Macintosh is still miles
  162. ahead of most of its competitors, simply because there are at least
  163. standards for many aspects of the interaction between application
  164. and user, such as the placement of scroll bars, the use of double clicks
  165. or the shape of the mouse cursor.
  166. .FE
  167. .PP
  168. With these considerations in mind, we set out to design a `generic'
  169. window system interface.
  170. .sp
  171. .IP \(bu
  172. The interface should be general enough to suit the needs of many
  173. different programs.
  174. Thus, it should be reasonably rich in functionality, e.g., provide both
  175. textual and graphical output, handle keyboard, mouse and menu-based
  176. input, support multiple windows, etc.
  177. .IP \(bu
  178. It should be simple to use.
  179. Including one header file and calling a
  180. small number of routines (with not too many parameters!) should suffice
  181. for the creation of a full-function window and the definition of its
  182. contents.
  183. As much as possible, the programmer should only be bothered with issues
  184. that matter from the program's point of view.
  185. In other words, the interface should be `high level'.
  186. .IP \(bu
  187. And most of all, it should be realistically portable; each potential
  188. feature should be weighed in the light of its implementability using
  189. different systems, including several popular micros.
  190. .sp
  191. .LP
  192. The requirement of portability is necessarily both good and bad.
  193. It is bad because it can sometimes make an elegant solution unfeasible,
  194. imposing seemingly random restrictions.
  195. But it is good because it makes the design stick to reality, and limits
  196. it to the `essence' of window systems, rather than allowing the
  197. designers to invent yet another incompatible paradigm.
  198. And sometimes the `helicopter view' gained from looking at
  199. solutions chosen by vastly different window systems for a particular
  200. problem has shown the way to an entirely new view, simplifying it by
  201. generalization.
  202. .sp
  203. .LP
  204. A large part of the paper is devoted to a detailed description of
  205. STDWIN's functionality from a programmer's point of view.
  206. First the `core' of the package is described, explaining the basic
  207. output and input facilities;
  208. then some extra facilities are briefly discussed.
  209. Interspersed are comments on the rationale for particular solutions,
  210. some hints on the implementation, and warnings about non-portable uses.
  211. At the end the paper returns to the more philosophical issues:
  212. experiences, future developments, food for thought.
  213. .NH
  214. Description
  215. .LP
  216. .NH 2
  217. Header file
  218. .LP
  219. Applications wishing to use STDWIN must place a line saying
  220. .CW "#include <stdwin.h>"
  221. near the top of their source file(s).
  222. All user-visible external names defined in this header file start with
  223. .CW w
  224. or
  225. .CW W .
  226. external names used internally by implementations begin with
  227. .CW _w
  228. or
  229. .CW _W .
  230. .NH 2
  231. Initialization and clean-up
  232. .LP
  233. Before starting to use STDWIN, the initialization routine
  234. .CW "winit()"
  235. must be called.
  236. Before exiting, the application should call
  237. .CW "wdone()"
  238. to perform any necessary clean-up operations.
  239. .PP
  240. These calls can't be repeated; after
  241. .CW "wdone()"
  242. has been called the application cannot call
  243. .CW "winit()"
  244. again and `return to life'.
  245. .NH 2
  246. Creating and destroying windows
  247. .LP
  248. A new window is created by calling
  249. .CW "wopen(title, drawproc)" .
  250. .I Title
  251. is a string identifying the window to the user; it is usually displayed
  252. by STDWIN in the window's border, e.g., in a title bar.
  253. .I Drawproc
  254. is the address of the window's draw procedure (see next section), or
  255. NULL if the window is not to have a draw procedure.
  256. STDWIN windows look like windows in the usual style of the underlying
  257. window system, usually with a title bar, scroll bars etc.
  258. Position, size and other characteristics of the new window are
  259. determined by STDWIN (but see below).
  260. .PP
  261. .CW "Wopen"
  262. returns a
  263. .I "window pointer" ,
  264. of type
  265. .CW "WINDOW *" ,
  266. to be used to identify the window in subsequent operations.
  267. If creation of the window failed, a NULL pointer is returned.
  268. .PP
  269. STDWIN allows an application to have multiple windows open simultaneously.
  270. Implementations usually impose a limit on the number of open
  271. windows; when this limit is reached,
  272. .CW "wopen"
  273. returns NULL, and the application should try to close other windows
  274. (or prompt the end user to close them).
  275. .PP
  276. A window is deleted permanently by calling
  277. .CW "wclose(win)" .
  278. Windows can be deleted only by the application.
  279. The end user can send a request to the application to close a window,
  280. but the application may ignore the request or postpone its execution.
  281. .PP
  282. There is no explicit way to iconize
  283. a window (i.e., to temporarily close it, leaving an icon in its place).
  284. On systems where window iconization is built into the window system,
  285. STDWIN may support it silently; all the application notices is that no
  286. input is received for iconized windows.
  287. .NH 3
  288. Changing defaults
  289. .LP
  290. When a window is opened STDWIN determines
  291. a default size and position for it.
  292. Usually this is convenient for the application (which needn't
  293. have its own algorithm for placing multiple windows, for example),
  294. but sometimes finer control is desirable.
  295. Therefore, a number of default-setting routines are provided:
  296. .LP
  297. .CW "wsetdefwinsize(width, height)"
  298. .IP
  299. Changes the default window size.
  300. This sets the net size, excluding borders, scroll bars etc.
  301. .LP
  302. .CW "wsetdefwinpos(h, v)"
  303. .IP
  304. Changes the default window position.
  305. This default is usually not a constant but a dynamically computed value.
  306. The next opened window will be placed at
  307. .I "(h, v)" ;
  308. the position of windows opened after that may be a more complicated
  309. function of
  310. .I h
  311. and
  312. .I v .
  313. .LP
  314. These routines may be called at any time; they affect only windows
  315. opened after their call.
  316. A negative or zero parameter restores the default for that
  317. dimension.
  318. Other values are clipped or rounded to reasonable and implementable
  319. values; these routines are best seen as giving hints to STDWIN, which
  320. may be ignored by some implementations.
  321. .NH 2
  322. The output model
  323. .LP
  324. A STDWIN window is a view on a possibly much larger area,
  325. a rectangle referred to as its
  326. .I document ,
  327. in which the application draws its output.
  328. The document's size is chosen by the application, and can be changed at
  329. any time by calling
  330. .CW "wsetdocsize(win, width, height)" .
  331. It is not limited by window or screen size, nor indeed by available
  332. memory; the entire document's contents are not stored directly.
  333. The end user has the freedom to `pan' the window over the document's
  334. surface, using scroll bars or a similar mechanism.
  335. When a particular part of the document is to be visible in the window,
  336. STDWIN asks the application to repaint that area.
  337. It is not forbidden to draw outside the document, but the end
  338. user normally can't pan outside the document (unless the window is
  339. larger than the document).
  340. .PP
  341. There are two mechanisms for repainting: a low-level mechanism using
  342. DRAW events, and a higher-level mechanism using a
  343. .I "draw procedure" .
  344. .PP
  345. DRAW events are merged with the general event stream (see below); when
  346. no other events are in the event queue, STDWIN looks to see if
  347. there is any window needing a repaint, and if so, it passes a DRAW event
  348. for that window to the application.
  349. A DRAW event includes as additional information the rectangle
  350. that is to be repainted.
  351. The application should react by erasing and repainting that rectangle
  352. (or a larger part of the document).
  353. .PP
  354. Normally, however, windows have an associated
  355. .I "draw procedure" .
  356. This is a procedure (defined by the application) which knows how to draw
  357. the entire document, or any sub-rectangle of it.
  358. When STDWIN is about to generate a DRAW event for a window with a draw
  359. procedure, it prepares the window for drawing, erases the rectangle
  360. that needs repainting, and calls the draw procedure with the window and
  361. the rectangle as parameters.
  362. The advantage of this mechanism over DRAW events is the possibility for
  363. certain STDWIN implementations to clip the output to a smaller,
  364. non-rectangular area that really needs a repaint; also somewhat simpler
  365. event decoding logic for the application.
  366. .PP
  367. Usually, the end user controls which part of the document is visible in
  368. the window (by manipulating the scroll bars).
  369. However, there are times when an application wants to display a particular
  370. part of the document, e.g. to show the effect of a search operation.
  371. It can then call
  372. .CW "wshow(win, <rectangle>)"
  373. to indicate that the given rectangle should be visible, if at all
  374. possible.
  375. STDWIN will check whether this is already the case, and if not, move
  376. the window with respect to the document to make it visible.
  377. There is also a lower-level call,
  378. .CW "wsetorigin(win, <point>)"
  379. which makes the given point in the document the top left corner of the
  380. window.
  381. .PP
  382. When the application wants to change part of the document, it can
  383. directly paint the changes (after preparing for drawing in that
  384. particular window).
  385. However, it is often more appropriate to delay the actual painting until
  386. after other input has been processed.
  387. It is possible to tell STDWIN that a particular area of the document
  388. needs repainting by calling
  389. .CW "wchange(win, <rectangle>)" .
  390. At the appropriate time, a DRAW event for this rectangle (possibly
  391. merged with other areas that need repainting) will be generated, or the
  392. window's draw procedure will be called.
  393. .PP
  394. When the repaint area is non-rectangular (e.g., it is the union of
  395. several rectangles), the application is asked to repaint the smallest
  396. rectangle that encloses the repaint area.
  397. This may occasionally cause more repainting than absolutely necessary,
  398. resulting in extra delays; since the repainting is limited to the window
  399. size, however, the costs won't be excessive in most cases.
  400. The choice was made here for a simple interface to the draw procedure,
  401. avoiding dynamic data structures.
  402. For the needs of the highest-demanding applications, an enquiry routine
  403. returning the exact repaint area may have to be be added
  404. (or a function telling
  405. whether a particular rectangle intersects the repaint area).
  406. .NH 2
  407. Drawing in a document
  408. .NH 3
  409. The coordinate system
  410. .LP
  411. STDWIN provides a single coordinate system per window.
  412. Coordinates are integers, with the X axis pointing right and the Y axis
  413. pointing down.
  414. In order to avoid confusion with other conventions, the axes
  415. are never called X and Y axis but h and v axis.
  416. H coordinates are always listed first.
  417. The origin (0, 0) is the top left corner of the document.
  418. Unit size equals pixel size on the screen; thus, documents inherit the
  419. screen's aspect ratio.
  420. Pixels on different machines can vastly differ in size; e.g.,
  421. on alphanumerical terminals,
  422. pixel size might well equal character cell size.
  423. Therefore, applications should scale their drawings accordingly.
  424. STDWIN provides enquiry functions to tell the physical size of a pixel.
  425. An alternative approach, suitable for applications that display mostly
  426. text, is to scale the drawing accordingly to the dimensions of
  427. characters drawn on the screen.
  428. Text measuring functions are available for this purpose (see below).
  429. .NH 3
  430. Preparation for drawing
  431. .LP
  432. Since a picture is usually built out of a large number of calls to
  433. primitive drawing operations, it would be annoying to have to specify
  434. a window parameter on each call.
  435. STDWIN requires the application to say in which window it wants to
  436. draw before using any drawing primitives, by calling
  437. .CW "wbegin\%draw\%ing(win)" .
  438. After the drawing is done, the application should call
  439. .CW "wend\%draw\%ing(win)" ,
  440. telling STDWIN to flush the output to the screen.
  441. .PP
  442. In a draw procedure these calls are unnecessary; there, all drawing
  443. operations apply to the given window, and output is flushed when the
  444. draw procedure returns.
  445. .NH 3
  446. Graphical primitives
  447. .LP
  448. STDWIN currently provides a small set of graphical primitives.
  449. This set will be extended when the need arises.
  450. All primitives except
  451. .CW werase
  452. and
  453. .CW winvert
  454. draw in OR mode, i.e., they only add black pixels to the drawing
  455. and never erase pixels.
  456. Note that points are actually given as two integer parameters, h and v;
  457. rectangles are given as four integer parameters:
  458. left, top, right and bottom.
  459. Rectangles always refer to the area enclosed by infinitely thin
  460. boundary lines; e.g., the rectangle (0, 0, 1, 1) encloses a 1 by 1
  461. square whose top left corner is the origin (0, 0).
  462. .PP
  463. Functions currently defined are:
  464. .LP
  465. .CW "wdrawline(<point1>, <point2>)"
  466. .IP
  467. Draws a line from point1 to point2.
  468. .LP
  469. .CW "wdrawbox(<rectangle>)"
  470. .IP
  471. Draws a box (i.e., a rectangle) inside the given rectangle.
  472. .LP
  473. .CW "wdrawcircle(<point>, radius)"
  474. .IP
  475. Draws a circle with the specified radius around the given point as
  476. center.
  477. .LP
  478. .CW "wpaint(<rectangle>)"
  479. .IP
  480. Paints the area inside the given rectangle black.
  481. .LP
  482. .CW "werase(<rectangle>)"
  483. .IP
  484. Erases the area inside the given rectangle.
  485. .LP
  486. .CW "winvert(<rectangle>)"
  487. .IP
  488. Inverts the pixels in the given rectangle.
  489. .LP
  490. .CW "wshade(<rectangle>, percentage)"
  491. .IP
  492. Adds a shading pattern to the given rectangle, approximately making the
  493. given percentage of all pixels black.
  494. Thus, a percentage of 0 has no effect;
  495. a percentage of 50 sets every other pixel;
  496. a percentage of 100 is equivalent to
  497. .CW "wpaint(<rectangle)" .
  498. The exact shading pattern used is implementation-dependent, as are the
  499. values to which percentages are rounded.
  500. .NH 3
  501. Text drawing primitives
  502. .LP
  503. STDWIN supports the drawing of characters in a font which may be
  504. proportionally spaced, depending on the implementation.
  505. The exact shape and size of the characters are implementation-dependent.
  506. STDWIN does not use the notion of a `base line' on which characters are
  507. drawn; rather, when a character or string is to be drawn, the top left
  508. corner of the box around it is given.
  509. All boxes have the same height, and a width appropriate for the
  510. character, so characters drawn in adjacent boxes `look right'.
  511. This approach has the advantage that the application needn't be
  512. concerned with such font parameters as base line, ascent, descent and
  513. leading; it can simply start drawing characters at (0, 0) and they
  514. will come out `right'.
  515. (This advantage for simplistic applications may turn into a disadvantage
  516. for programs wishing precise control over the placement of characters.
  517. In that case, additional enquiry functions will have to be defined
  518. to remedy this situation.)
  519. .PP
  520. The call
  521. .CW "wdrawchar(<point>, character)"
  522. draws the given character with its top left corner at the given point.
  523. It returns the h coordinate of the right edge of the box in which the
  524. character is drawn; this is the `natural' h coordinate for a character
  525. to be drawn next to it.
  526. .PP
  527. The call
  528. .CW "wdrawtext(<point>, string, length)"
  529. draws the characters of the given string starting with the top left
  530. corner at the given point.
  531. .I Length
  532. indicates the number of characters in the string;
  533. if negative, the string ends with a NUL character.
  534. .CW Wdrawtext
  535. returns the h coordinate of the right edge of the box in which the
  536. last character is drawn.
  537. Note that no special interpretation is given to characters like
  538. .CW \&'\en'
  539. or
  540. .CW \&'\et' ;
  541. they may be displayed as spaces or funny graphics.
  542. .NH 3
  543. Text measuring primitives
  544. .LP
  545. The dimensions of characters drawn by the above functions depend on the
  546. font used.
  547. Future versions may implement font and size changes under application
  548. control; currently these are fixed by the implementation.
  549. For applications that want to know in advance how big the strings they
  550. are drawing will be, there are functions to measure text dimensions.
  551. Unlike the drawing primitives,
  552. the text measuring primitives and the style-changing primitives
  553. described in the next section can be called anywhere.
  554. .PP
  555. The following text-measuring functions are defined:
  556. .LP
  557. .CW "wlineheight()"
  558. .IP
  559. Gives the vertical height of the boxes in which characters are drawn.
  560. This is the same for all characters, and the value delivered gives a
  561. `natural-looking' line spacing when lines are drawn at v coordinates
  562. with increments of this value.
  563. .LP
  564. .CW "wcharwidth(character)"
  565. .IP
  566. Computes the width of the box in which the given character will be drawn.
  567. .LP
  568. .CW "wtextwidth(string, length)"
  569. .IP
  570. Computes the width of the box in which the string will be drawn.
  571. .I Length
  572. indicates the number of characters in the string;
  573. if negative, the string ends with a NUL character.
  574. .LP
  575. .CW "wtextbreak(string, length, width)"
  576. .IP
  577. Computes the number of characters from the string that will fit in a box
  578. of the given width (in pixels).
  579. .I Length
  580. is interpreted as above.
  581. .NH 3
  582. Text style
  583. .LP
  584. Future versions of STDWIN will have to worry about mixing fonts,
  585. type sizes and text styles.
  586. Currently applications have no control over the font and size used, and
  587. can only control one aspect of text style;
  588. different window systems differ so much
  589. in their support of font names, font scaling, style combinations and so
  590. on, that it seemed wise to avoid these issues in the
  591. first version (however, some implementations have a way to influence
  592. the font, size or style used at initialization time).
  593. The only calls currently available are those to change between normal,
  594. black on white characters and inverse, white on black characters; this
  595. is needed to display the focus in the text-editing package (see below).
  596. .PP
  597. The call
  598. .CW "wsetinverse()"
  599. sets the text style to inverse characters; the call
  600. .CW "wsetplain()"
  601. reverts the text style back to normal.
  602. The text style is a global attribute, so draw procedures that change it
  603. should reset it to normal before leaving.
  604. .NH 3
  605. Scrolling
  606. .LP
  607. Applications like text editors often have a need for deleting a
  608. horizontal or vertical slice from their document; e.g., after a text
  609. editor has deleted a couple of lines, the remaining lines must be moved
  610. up in the document.
  611. Although it is theoretically possible to do this by calling
  612. .CW "wchange"
  613. for the remaining part of the document (assuming the draw procedure
  614. knows that the v coordinates of the affected lines have changed),
  615. this often involves a lot of drawing which could have been avoided by
  616. applying a `bit copy' operation as available in many systems,
  617. combined with only a little bit of redrawing
  618. (e.g., for lines `scrolled in' from below the window border).
  619. .PP
  620. The call
  621. .CW "wscroll(win, <rectangle>, dh, dv)"
  622. is provided to help in situation.
  623. It should be called outside the drawing procedure,
  624. where the call to
  625. .CW wchange
  626. would otherwise be placed.
  627. If the particular STDWIN implementation supports the requested type of
  628. bit scroll operation, it will scroll the bits inside the given
  629. rectangle by an amount of
  630. .I dh
  631. to the right and by
  632. .I dv
  633. downward.
  634. (Negative values mean scrolling to the left or upward, respectively.)
  635. No bits outside the given rectangle are affected or used:
  636. bits `scrolled out' of the rectangle will simply be thrown away; for
  637. the area that is to be `scrolled in' from outside the rectangle,
  638. .CW wchange
  639. is called internally.
  640. If the particular form of bit scrolling required isn't supported,
  641. the entire call is equivalent to
  642. .CW "wchange(win, <rectangle>)" ,
  643. relying on the normal repaint mechanism to update the window.
  644. .NH 2
  645. The input model
  646. .LP
  647. Interactive input is presented to the application in the form of
  648. .I events .
  649. Examples of events are `a character has been typed' or `the mouse button
  650. has been pressed'.
  651. Some other information generated asynchronously by STDWIN is also passed
  652. in the form of events.
  653. .PP
  654. Events are queued internally; the routine
  655. .CW "wgetevent"
  656. gets the next event from the queue and passes it to the application.
  657. If the queue is empty, it waits until an event arrives first.
  658. (Certain events, like DRAW events, are not really queued but constructed
  659. on the fly when the queue is empty.)
  660. .PP
  661. Some applications don't want to wait when no event is ready, but do want
  662. to process events that are already queued.
  663. For such cases there is the alternative routine
  664. .CW "wpollevent"
  665. which acts like
  666. .CW "wgetevent"
  667. when an event is available from the queue, but returns immediately with
  668. a dummy NULL event when the queue is empty.
  669. .PP
  670. An event always applies to a particular window.
  671. This means that an application which has no window open is blind and deaf.
  672. When an application calls
  673. .CW "wgetevent"
  674. in this state, it is terminated.
  675. Therefore, applications should make sure to always open a window before
  676. calling
  677. .CW wgetevent .
  678. .PP
  679. STDWIN implementations may limit the size of the event queue; when the
  680. queue is filled up events may get lost without notification.
  681. (There is no way to prevent this, since the problem usually occurs in
  682. the underlying operating system.)
  683. .NH 2
  684. Events
  685. .LP
  686. Events are typically read in a `main event loop', which might look
  687. something like this:
  688. .DS
  689. .CW
  690. int stop= 0;
  691. while (!stop) {
  692.     EVENT e;
  693.     wgetevent(&e);
  694.     switch (e.type) {
  695.         ...
  696.     }
  697. }
  698. .R
  699. .DE
  700. The variable
  701. .CW e
  702. is called the
  703. .I "event record" .
  704. The information placed in the event record depends on the event type.
  705. For all event types, the type is available as
  706. .CW "e.type" ,
  707. and the window to which the event applies as
  708. .CW "e.window" ;
  709. additional information is listed with the individual event descriptions.
  710. This additional information is stored in a
  711. union named
  712. .CW e.u ,
  713. e.g.,
  714. .CW e.u.character
  715. for character input events.
  716. .PP
  717. For clarity, events are always referred to by their `informal' names in this
  718. paper, e.g., MOUSE DOWN.
  719. The actual constants defined by STDWIN are derived from the informal
  720. name by prepending
  721. .CW WE_
  722. and replacing spaces by underscores, yielding, e.g.,
  723. .CW WE_MOUSE_DOWN .
  724. .PP
  725. Events can be classified as mouse events, other user input events and
  726. STDWIN-generated events.
  727. .NH 3
  728. Mouse events
  729. .LP
  730. Mouse events are generated when the user presses a mouse button inside
  731. the visible part of a document displayed in a window.
  732. There are separate event types for a press of a button, moves while
  733. a button is held down, and a release of a button.
  734. The position of the mouse cursor at the time the event was generated is
  735. reported in (\c
  736. .CW e.u.where.h ,
  737. .CW e.u.where.v ).
  738. The button number
  739. (1, 2 or 3 on a three-button mouse; always 1 on a one-button mouse)
  740. is reported in
  741. .CW e.u.where.button .
  742. .PP
  743. Mouse events allows easy detection of
  744. .I "multiple clicks" ,
  745. to which many applications want to assign a special meaning.
  746. Successive presses on a mouse button are considered to be part of a
  747. click sequence if they are `close together' in space and time.
  748. When a mouse button is pressed, STDWIN checks whether it is close enough
  749. to the previous press to be considered a continuation of the same click
  750. sequence, and if so, notes the number of the current click in
  751. .CW e.u.where.click .
  752. A click that is unrelated to previous clicks has click number 1;
  753. a following related click has click number 2, the next one has number
  754. 3, and so on, until the mouse is moved too far away or the user waits
  755. too long, in which case the click number is reset to 1 at the next
  756. mouse event.
  757. This way of reporting multiple clicks requires no delay to see whether a
  758. click is part of a multiple-click sequence; mouse events are reported as
  759. soon as they happen.
  760. .PP
  761. Not all STDWIN implementations run on machines whose mouse has more than
  762. one button; it is therefore unwise to write an application which can
  763. perform certain operations only through buttons 2 or 3.
  764. If multiple buttons are held down simultaneously, only events for the
  765. button pressed first are generated.
  766. .PP
  767. The mouse event types are
  768. MOUSE DOWN
  769. for a button press,
  770. MOUSE MOVE
  771. for a move of the mouse cursor while a button is still depressed, and
  772. MOUSE UP for a button release.
  773. The click number for MOUSE MOVE events is always zero.
  774. In order to prevent filling up the event queue, multiple MOUSE MOVE
  775. events may be collapsed to a single event, giving only the last mouse
  776. position.
  777. When the user moves the mouse outside the window with a button held
  778. down, the mouse remains associated with the window, and its position is
  779. reported relative to the origin of the window's document.
  780. The click number for a MOUSE UP event is the same as that of the
  781. corresponding MOUSE DOWN event if the mouse wasn't moved too far from
  782. its original position, or zero if it was moved further (and in this case
  783. this event is the end of its click sequence).
  784. .NH 3
  785. Other user input events
  786. .IP CHAR
  787. .br
  788. The user has typed a character at the keyboard.
  789. Its ASCII value is reported in
  790. .CW e.u.character .
  791. Note that some special keys (like RETURN, TAB, BACKSPACE) do not send
  792. CHAR events but COMMAND events.
  793. .IP COMMAND
  794. .br
  795. .RS
  796. This event is sent for special keys on the keyboard, and for certain
  797. special actions recognized by STDWIN.
  798. Some keys do not generate CHAR events but COMMAND events, because they
  799. do not send the same ASCII code on all keyboards (e.g., Enter), or
  800. because there are no standard ASCII codes for them (e.g., arrows and
  801. function keys).
  802. A code telling which special command was meant is reported in
  803. .CW e.u.command .
  804. Possible values represent the following keys and standard actions:
  805. CANCEL, TAB, RETURN, BACKSPACE, LEFT, RIGHT, UP, DOWN and CLOSE; this
  806. list may be extended in the future.
  807. The constants are actually called
  808. .CW WC_CANCEL
  809. etc.
  810. .PP
  811. CLOSE is to be interpreted as a request to close the window; the key
  812. or other action that generates it is system-dependent.
  813. The application should close the window, possibly after verifying that
  814. any changes the user has made to the file displayed in the window have
  815. been saved, in which case it may ignore the request,
  816. or put up a dialogue box asking what should be done to the file.
  817. .RE
  818. .IP MENU
  819. .br
  820. .RS
  821. A menu item was selected.
  822. The menu id and item number of the selected item are reported in
  823. .CW e.u.m.id
  824. and
  825. .CW e.u.m.item ;
  826. menu items are numbered starting at 0
  827. (see below for the definition of menus).
  828. .PP
  829. The interaction technique used to select menu items is not defined by
  830. STDWIN; a suitable technique is chosen by each implementation, e.g.
  831. pop-up, push-down or permanently present menus.
  832. Keyboard shortcuts are usually also available.
  833. The application cannot distinguish between the various ways of selecting
  834. a particular menu item; all it sees is which item is selected.
  835. .RE
  836. .NH 3
  837. STDWIN-generated events
  838. .IP NULL
  839. .br
  840. Nothing happened.
  841. This is a dummy event reported only by
  842. .CW "wpollevent"
  843. when the event queue is empty.
  844. .IP ACTIVATE
  845. .br
  846. A window has been `activated'.
  847. This is usually caused by the end user selecting an inactive window with
  848. the mouse.
  849. Only one window can be active at any time.
  850. This usually means that all subsequent keyboard input applies to
  851. the active window; some applications want to change the highlighting of
  852. selected objects in a document when its window is active.
  853. (Highlighting of the window's title, etc. is done
  854. automatically by STDWIN.)
  855. After a window is opened, the first event applying to it is
  856. usually an ACTIVATE event (because windows are opened in an unactivated
  857. state).
  858. Applications needn't monitor ACTIVATE events if all they want
  859. is determining to which window keyboard input applies; the relevant
  860. window is reported with each event in
  861. .CW e.window .
  862. .IP DEACTIVATE
  863. .br
  864. A window has been `deactivated'.
  865. This usually occurs just before another window is activated.
  866. In many implementations of STDWIN it is possible for the user to
  867. activate a window not belonging to the current application; in this case
  868. the current application receives only a DEACTIVATE event until one of
  869. its windows is reactivated.
  870. Note that closing a window does not generate a DEACTIVATE event for it,
  871. since the window has already disappeared by the time the application can
  872. call
  873. .CW "wgetevent" .
  874. .IP SIZE
  875. .br
  876. .RS
  877. A window's size has changed.
  878. This is usually done by the user explicitly resizing the window;
  879. in some (`tiling') STDWIN implementations it can also be caused by
  880. opening or closing other windows.
  881. .PP
  882. Some applications want to format their documents to fit exactly in the
  883. window.
  884. SIZE events make it possible for such applications to monitor window
  885. size changes.
  886. The new window size is not reported in the event record; the application
  887. can use the enquiry function
  888. .CW wgetwinzize
  889. for this purpose (see below).
  890. .PP
  891. Note that window moves don't generate events
  892. (except possibly DRAW events).
  893. .RE
  894. .IP DRAW
  895. .br
  896. This event is reported only for windows without an associated draw
  897. procedure.
  898. It means that part of the window needs to be repainted.
  899. The smallest rectangle enclosing the area to be repainted is reported in
  900. .CW e.u.area ,
  901. a struct with four fields
  902. .CW left ,
  903. .CW top ,
  904. .CW right
  905. and
  906. .CW bottom .
  907. .IP TIMER
  908. .br
  909. The window's alarm timer has gone off.
  910. For each window, an alarm may be set with the call
  911. .CW "wsettimer(win, dsecs)" .
  912. The alarm will go off, causing a TIMER event,
  913. aproximately
  914. .I dsecs/10
  915. seconds in the future (\c
  916. .I dsecs
  917. meaning deciseconds).
  918. Only one alarm per window is maintained; a new call overrides the
  919. previously set alarm.
  920. A value of 0 cancels the alarm.
  921. Timer values may be rounded up to whole seconds by some implementations.
  922. The maximum timer value that is guaranteed to be supported is
  923. 32000 dsecs.
  924. .NH 2
  925. Pushing events back
  926. .LP
  927. Occasionally, an application may want to postpone processing of an event
  928. till later.
  929. E.g., a subroutine may be getting events in a loop until it
  930. receives an event which shouldn't be handled locally but in the main
  931. event loop.
  932. The routine
  933. .CW "wungetevent(&eventrecord)"
  934. allows an event to be pushed back onto the event queue; the next
  935. call to
  936. .CW wgetevent
  937. or
  938. .CW wpollevent
  939. will report the event just pushed back.
  940. Only a single event can be pushed back (some implementations save the
  941. pushed back event in a separate buffer).
  942. It is possible to modify the event before pushing it back, or to
  943. synthesize events entirely.
  944. .NH 2
  945. Getting and setting the active window
  946. .LP
  947. A pointer to the active window is returned by the function
  948. .CW "wactive()" .
  949. The application can also make a different window active by calling
  950. .CW "wsetactive(win)" .
  951. This call does not take effect immediately; some time in the future, a
  952. DEACTIVATE event for the currently active window and an ACTIVATE event
  953. for the newly activated will be received.
  954. .NH 2
  955. Menus
  956. .LP
  957. Most window systems provide a simple way to set up and manipulate menus,
  958. in their simplest form lists of text strings which can be selected by
  959. the user by clicking on a string with the mouse.
  960. Menus may `pop up' when a particular mouse button is pressed in a
  961. particular screen area, or be `pulled down' from a `menu bar', etc.
  962. STDWIN provides a consistent, simple way for the application to
  963. interface with standard menus, or with menus defined entirely by the
  964. STDWIN library (if the window system provides no usable menus).
  965. .PP
  966. A
  967. .I menu
  968. contains a number of
  969. .I items ,
  970. numbered starting at 0.
  971. A menu has a
  972. .I title ,
  973. a text string displayed to identify the menu to the user, and a
  974. .I "menu id" ,
  975. a small positive integer identifying the menu to the application.
  976. Each item contains a text string, an optional
  977. .I "check mark"
  978. (which may be set by the application to indicate whether an option
  979. controlled by a menu item is active), and can be
  980. .I enabled
  981. or
  982. .I disabled .
  983. Only enabled items are selectable.
  984. When the user selects an enabled item, a MENU event is queued containing
  985. the menu id and item number in the event record.
  986. Because of the way events are queued, it is possible to receive MENU
  987. events for disabled menu items
  988. (if the selection was made before the menu item was disabled);
  989. applications should be prepared to receive spurious menu selection events.
  990. .PP
  991. A menu is created by a call to
  992. .CW "wmenucreate(id, title)" ;
  993. this returns a
  994. .I "menu pointer"
  995. which must be used for all further manipulations with the menu.
  996. .I Id
  997. is the menu id, which should be in the range [1..255].
  998. Menu ids should be unique within an application.
  999. .PP
  1000. Initially, a menu contains no items.
  1001. Items are added by calling
  1002. .CW "wmenuadditem(mp, text, shortcut)" .
  1003. The new item's number equals the number of items in the menu before this
  1004. call; it is returned as the function value.
  1005. .I Mp
  1006. is the menu pointer;
  1007. .I text
  1008. is the item text.
  1009. The item is initially enabled and unchecked.
  1010. .I Shortcut
  1011. is a character used to construct a `keyboard shortcut' for the
  1012. menu item; \-1 means the item is not to have a shortcut.
  1013. (The interpretation of keyboard shortcuts is implementation-dependent.
  1014. In a typical STDWIN implementation,
  1015. a menu item with shortcut `X' might be selected by typing ESC-X
  1016. or Meta-X (but not Control-X).
  1017. All printable characters are acceptable as shortcuts,
  1018. but on some systems lower case and upper case are indistinguishable.)
  1019. Adding an item with an empty string as text adds a disabled
  1020. `separator' item.
  1021. .PP
  1022. The text of an existing menu item can be changed by calling
  1023. .CW "wmenusetitem(mp, number, text)" .
  1024. Items can be enabled or disabled by calling
  1025. .CW "wmenuenable(mp, number, flag)" .
  1026. The check mark for an item can be set or cleared by calling
  1027. .CW "wmenucheck(mp, number, flag)" .
  1028. .PP
  1029. A menu can be deleted by calling
  1030. .CW "wmenudelete(mp)" .
  1031. Note that individual menu items, once added, cannot be removed, nor can
  1032. new items be inserted in the middle.
  1033. This is due to restrictions in many window systems' menu interfaces;
  1034. usually menus are sufficiently static that it doesn't matter.
  1035. .PP
  1036. For a menu's items to be selectable, the menu must be attached to a
  1037. window and the window must be activated.
  1038. Normally, STDWIN automatically attaches all menus to all windows, so all
  1039. menus become selectable as soon as the first window is activated.
  1040. To change this behaviour, the call
  1041. .CW "wmenusetdeflocal(TRUE)"
  1042. causes subsequently created menus to be `local', requiring
  1043. explicit attachment and detachment.
  1044. The call
  1045. .CW "wmenuattach(win, mp)"
  1046. attaches the menu
  1047. .I mp
  1048. to the window
  1049. .I win .
  1050. The call
  1051. .CW "wmenudetach(win, mp)"
  1052. reverses this effect.
  1053. A menu may be attached to multiple windows; multiple menus may be
  1054. attached to a window.
  1055. After calling
  1056. .CW "wmenusetdeflocal(FALSE)" ,
  1057. future menus will be `global' again, i.e., automatically attached to all
  1058. (existing and new) windows.
  1059. .NH
  1060. Additional facilities
  1061. .LP
  1062. .NH 2
  1063. Enquiry functions
  1064. .LP
  1065. Some enquiry functions are available to interrogate the system state.
  1066. .LP
  1067. .CW "wgetscrsize(&width, &height)"
  1068. .IP
  1069. Returns the screen size measured in pixels into the integer variables
  1070. whose addresses are passed.
  1071. .LP
  1072. .CW "wgetscrmm(&mmwidth, &mmheight)"
  1073. .IP
  1074. Returns the approximate screen size measured in millimeters.
  1075. By combining this information with the outcome of
  1076. .CW wgetscrsize ,
  1077. pixel size and aspect ratio can conveniently be computed.
  1078. In some (most?) implementations, the numbers returned may be
  1079. approximations or guesses.
  1080. .LP
  1081. .CW "wgetwinsize(win, &width, &height)"
  1082. .IP
  1083. Returns the size of the drawable area of a window, measured in pixels.
  1084. (Due to the presence of borders, a maximally-sized window is usually
  1085. smaller than the screen.)
  1086. .NH 2
  1087. The text caret
  1088. .LP
  1089. In documents that deal with text it is often useful to have some form of
  1090. `text cursor', indicating the position where characters typed at the
  1091. keyboard will be inserted.
  1092. The call
  1093. .CW "wsetcaret(win, h, v)"
  1094. causes a `caret' to appear just to the left of the character
  1095. position (\c
  1096. .I h ,
  1097. .I v )
  1098. in the document.
  1099. The caret appears immediately before any character that
  1100. would be drawn by
  1101. .CW "wdrawtext(h, v, ...)" .
  1102. The caret has a system-defined shape; it is often a blinking vertical
  1103. bar.
  1104. .PP
  1105. Each window has its own caret; the caret in the active window may be
  1106. the only one that is visible, or it may blink while the carets in other
  1107. windows are static.
  1108. At any time a window has at most one caret; the old caret is removed
  1109. when a new one is specified.
  1110. The caret can be removed altogether with the call
  1111. .CW "wnocaret(win)" .
  1112. .NH 2
  1113. Dialogue tools
  1114. .LP
  1115. A
  1116. .I "dialogue box"
  1117. is a `mini-window' containing a simple message or question,
  1118. and requiring
  1119. the user to respond, e.g. by pressing a key or clicking the mouse in a
  1120. particular area.
  1121. As long as the dialogue box is present, the application is blocked.
  1122. After answering the question or acknowledging the message, the dialogue
  1123. box disappears and normal interaction with the application continues.
  1124. Dialogue boxes may be presented even when no windows are open yet.
  1125. The following calls put up dialogue boxes and wait for a response:
  1126. .sp
  1127. .LP
  1128. .CW "wmessage(string)"
  1129. .IP
  1130. Displays a message and waits until the user acknowledges it.
  1131. The precise form of acknowledgement required
  1132. is implementation-dependent;
  1133. it could be pressing the Return key or clicking an `OK button' with the
  1134. mouse.
  1135. .LP
  1136. .CW "waskstr(question, replybuf, buflength)"
  1137. .IP
  1138. Displays a question and waits until the user has finished typing a
  1139. reply.
  1140. The initial contents of the reply buffer are used as a default reply.
  1141. The function normally returns TRUE; if the user aborts the dialogue
  1142. (e.g., by pressing the CANCEL button) it returns FALSE.
  1143. .LP
  1144. .CW "waskync(question, dflt)"
  1145. .IP
  1146. Displays a question which gives the user the possibility to answer with
  1147. Yes, No or Cancel only.
  1148. The return value is 1 (Yes), 0 (No) or -1 (Cancel).
  1149. .I Dflt
  1150. is the suggested (default) return value.
  1151. .LP
  1152. .CW "waskfile(prompt, replybuf, buflength, new)"
  1153. .IP
  1154. Displays a dialogue box asking for a file name.
  1155. .I Replybuf
  1156. initially contains a default or suggested file name.
  1157. The boolean parameter
  1158. .I new
  1159. specifies whether a new (not yet existing) or old (existing) file is
  1160. required.
  1161. When a new file is asked for, the user may specify an existing file,
  1162. but in this case explicit permission is asked to overwrite it.
  1163. The function returns TRUE, or FALSE if the user aborts the dialogue.
  1164. The file name is returned in a form acceptable to the STDIO function
  1165. .CW fopen .
  1166. STDWIN implementations may provide additional support, e.g. file name
  1167. completion or file system browsing; the fact that some systems provide
  1168. elaborate standard file-selection dialogues (which is highly appreciated
  1169. by the end users) was a strong motivation to include this function in
  1170. STDWIN.
  1171. .LP
  1172. .CW "wperror(string)"
  1173. .IP
  1174. Displays an error message similar to that printed by the standard C
  1175. function
  1176. .I perror (3),
  1177. and waits for an acknowledgement as for
  1178. .CW wmessage .
  1179. .sp
  1180. .LP
  1181. It should be noted that
  1182. .CW "waskstr"
  1183. is the most general of the above functions; in theory, versions of the
  1184. others can be implemented with the help of
  1185. .CW "waskstr"
  1186. and other existing tools.
  1187. .NH 2
  1188. The text-editing package
  1189. .LP
  1190. The
  1191. .I text-editing
  1192. package is a set of routines implemented entirely `on top of' STDWIN,
  1193. without using any implementation-dependent functions or data structures.
  1194. The availability of this package
  1195. is important because it provides a standard way to tackle the
  1196. non-trivial problem of editing multi-line text blocks.
  1197. It is clearly influenced by the TextEdit routines available in the Apple
  1198. Macintosh's ROM Toolbox (but contains only original code).
  1199. .PP
  1200. The text-editing package displays a paragraph of text in a rectangle of
  1201. a given width, breaking the lines at spaces between words as necessary.
  1202. It gives the application complete control over what happens to the text,
  1203. but provides an easy way to handle user input intended to edit it.
  1204. .PP
  1205. The call
  1206. .CW "tecreate(win, <rectangle>)"
  1207. returns a pointer to a text-editing block at the specified position in
  1208. the given window's document.
  1209. (A text-editing block is not a portion of the document but a data
  1210. structure.)
  1211. Any number of text-editing blocks may be created, although usually at
  1212. most one block per window should be editable at any time.
  1213. .PP
  1214. Initially, the block contains no text.
  1215. The call
  1216. .CW "tesettext(tp, string)"
  1217. sets the text to be edited, replacing any existing text in the block.
  1218. The call
  1219. .CW "tegettext(tp)"
  1220. returns a pointer to the text string (which remains valid only until the
  1221. next call to a text-editing routine).
  1222. .PP
  1223. The text block is not automatically drawn.
  1224. When a text-editing routine changes the edited text (or other aspects of
  1225. its appearance), it calls
  1226. .CW wchange
  1227. for the appropriate area of the window; the window's draw procedure
  1228. should call
  1229. .CW "tedraw(tp)"
  1230. for each block which overlaps the repaint area.
  1231. .PP
  1232. Besides the edited string, a text-editing block contains a
  1233. .I focus ,
  1234. indicating which text is selected
  1235. for deletion or at which position new text will be inserted.
  1236. The focus can be set by the application with the call
  1237. .CW "tesetfocus(tp, first, last)" ,
  1238. telling that the characters in the range [first..last-1] are selected,
  1239. or, if first equals last, that the text insertion point is at that
  1240. position (characters are counted starting at 0).
  1241. If the focus is an insert position, the window's caret is set at that
  1242. position in the document.
  1243. Text can be inserted at the focus (replacing its previous contents) by
  1244. calling
  1245. .CW "tereplace(tp, string)" ;
  1246. specifying an empty string deletes any text in the focus.
  1247. .PP
  1248. The simplest way to let the user edit the text in a text-editing block
  1249. is to call
  1250. .CW "teevent(tp, &event\%record)"
  1251. for each event.
  1252. This call returns TRUE if the event is applicable to the text-editing
  1253. block (e.g., it is a CHAR event, or a mouse click within the block's
  1254. bounding rectangle), and in that case the event is processed by the
  1255. text-editing package (e.g., a character is inserted, or the focus is
  1256. moved to the point where the mouse was clicked).
  1257. If the event is not applicable to the particular block, the function
  1258. does nothing and returns FALSE; in this case the application should
  1259. further decide what to do to the event.
  1260. Of course, the application is free to decide whether to offer an event
  1261. to a text-editing block at all; e.g., it might have a different
  1262. interpretation for the Return key (for which the text-editing package
  1263. inserts a new-line character in the text string).
  1264. .PP
  1265. There are more text-editing calls, e.g. to move a text-editing block to
  1266. a new position, to enquire about the focus, to perform individual
  1267. editing operations, to ask for the height of the rectangle minimally
  1268. needed to display the text entirely, etc.
  1269. .PP
  1270. The following call displays a text string in exactly the same way as
  1271. the text-editing package would do (breaking it into lines at the same
  1272. places, etc.), but without creating a text-editing block, and thus
  1273. without a focus:
  1274. .CW "wdrawpar(<point>, string, width)" .
  1275. It returns the v coordinate of the bottom of the text paragraph.
  1276. To compute the height of a text paragraph thus drawn without actually
  1277. drawing it, one can call
  1278. .CW "wparheight(string, width)" .
  1279. .NH
  1280. A complete example
  1281. .LP
  1282. The program below is a complete STDWIN application.
  1283. It is presented here to give a feel for the use of some of the routines
  1284. described above.
  1285. The program displays a window in which a text-edit block is placed;
  1286. all events recognized by the text-edit package are handled correctly,
  1287. and so are several ways of quitting.
  1288. Other events are ignored.
  1289. .if t .sp .5v
  1290. .DS L
  1291. .CW
  1292. #include <stdwin.h>
  1293.  
  1294. TEXTEDIT *tp; /* Global so drawproc can reference it */
  1295.  
  1296. void drawproc(w, left, top, right, bottom)
  1297.     WINDOW *w;
  1298.     int left, top, right, bottom;
  1299. {
  1300.     tedraw(tp);
  1301. }
  1302. .R
  1303. .DE
  1304. .DS L
  1305. .CW
  1306. main()
  1307. {
  1308.     MENU *m;
  1309.     WINDOW *w;
  1310.     int stop;
  1311.     int width, height;
  1312. .R
  1313. .DE
  1314. .DS L
  1315. .CW
  1316.     winit();
  1317.     
  1318.     m= wmenucreate(1, "Sample");
  1319.     wmenuadditem(m, "Quit", 'Q'); /* Item 0 */
  1320.     
  1321.     w= wopen("Sample window", drawproc);
  1322.     wgetwinsize(w, &width, &height);
  1323.     tp= tecreate(w, 0, 0, width, height);
  1324. .R
  1325. .DE
  1326. .DS L
  1327. .CW
  1328.     stop= 0;
  1329.     while (!stop) {
  1330.         EVENT e;
  1331.         wgetevent(&e);
  1332.         if (teevent(tp, &e))
  1333.             wsetdocsize(w, width, tegetbottom(tp));
  1334.         else {
  1335.             switch (e.type) {
  1336.             case WE_COMMAND:
  1337.                 if (e.u.command == WC_CLOSE || e.u.command == WC_CANCEL)
  1338.                     stop= 1;
  1339.                 break;
  1340.             case WE_MENU:
  1341.                 if (e.u.m.id == 1 && e.u.m.item == 0) /* Quit */
  1342.                     stop= 1;
  1343.                 break;
  1344.             }
  1345.         }
  1346.     }
  1347. .R
  1348. .DE
  1349. .DS L
  1350. .CW
  1351.     wclose(w);
  1352.     wdone();
  1353.     exit(0);
  1354. }
  1355. .R
  1356. .DE
  1357. .if t .sp -.5v
  1358. .NH
  1359. Experiences
  1360. .LP
  1361. Five distinct STDWIN implementations have been created so far:
  1362. for the Apple Macintosh,
  1363. for the Whitechapel MG-1,
  1364. for X version 11,
  1365. for the Atari ST,
  1366. and a subset for alphanumeric displays
  1367. (which runs both under Unix and MS-DOS).
  1368. .PP
  1369. Once a STDWIN version for a target system is available,
  1370. application portability is high.
  1371. Most portability problems that crop up
  1372. (besides the usual problems like word size, byte order,
  1373. data alignment or following NULL pointers)
  1374. have to do with differences in other parts of the operating system
  1375. interface, e.g. use of the file system.
  1376. One portability problem encountered with the STDWIN interface was that
  1377. some programs developed for alphanumeric terminals expected a
  1378. fixed-width font; in general most problems were caused by insufficiently
  1379. precise specification of STDWIN.
  1380. .PP
  1381. The time needed to create a STDWIN version for a particular target
  1382. system is moderate.
  1383. An experienced C programmer who did not know anything about STDWIN or
  1384. the Atari ST in advance
  1385. created a working Atari ST version in two months.
  1386. So far, each version has been created more or less from scratch
  1387. (except for the common parts like the textedit package).
  1388. We have now gained enough experience with different target systems to be
  1389. able to create an intermediate layer containing code which remains more
  1390. or less constant between target systems.
  1391. .NH
  1392. Future developments
  1393. .LP
  1394. To date, the applications that use STDWIN have been mostly text-based.
  1395. Undoubtedly, this has influenced the direction of development of drawing
  1396. facilities in STDWIN.
  1397. It is sufficiently easy to add graphical primitives to an
  1398. implementation, though, that we expect to add several as demand grows,
  1399. e.g., bitblt, clipping, line styles, filling.
  1400. The existing facilities set a sort of standard for the form of future
  1401. ones.
  1402. The requirement that they be implementable on top of a large variety of
  1403. window systems will ensure that only more or less generally accepted
  1404. primitives will be included in STDWIN; a useful sort of conservatism for
  1405. a package that wants to enhance application portability.
  1406. .PP
  1407. Besides the need to add more drawing primitives, there are several areas
  1408. where STDWIN requires, and will probably get, extensions: fonts, sizes
  1409. and styles; the mouse cursor; drawing in off-screen bitmaps (not
  1410. associated with a window); error handling (which is currently virtually
  1411. absent); event queue manipulations and an `event mask'; `clipboard' or
  1412. `cut buffer' operations.
  1413. .PP
  1414. A development in a different direction, independent of the addition of
  1415. graphical primitives, may be the addition of more toolboxes built on
  1416. top of the exiting facilities, like the text editing package.
  1417. Tools are needed
  1418. to manipulate higher-order graphical objects,
  1419. to implement specific interaction techniques,
  1420. to provide `canned applications' like text-editing windows,
  1421. etc.
  1422. .PP
  1423. A third, potentially very useful, extension would be the addition of
  1424. drawable
  1425. `borders' to the window that aren't scrolled together with the document.
  1426. In such borders, interaction tools could be placed like palettes and
  1427. buttons, or rulers around the document.
  1428. The design of such an extension should be the topic of further research,
  1429. in order to achieve the largest possible generality.
  1430. .\" Filter troff input through refer -e -n
  1431. .[
  1432. $LIST$
  1433. .]
  1434.